﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class newstype : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["tid"] != null && Request.QueryString["op"] == "type")
            {
                rptdatabind();
            }
        }
    }
    protected void rpttypelist_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        switch (e.CommandName.ToLower())
        {
            case "check":
                string sql = string.Format(@"update news set nhot=nhot+1
where nid={0}", e.CommandArgument);
                YqhData obj = new YqhData();
                obj.ExecuteSql(sql);
                string url = string.Format("shownews.aspx?op=news&id={0}", e.CommandArgument);
                Response.Redirect(url);
                break;
        }
    }

    private void rptdatabind()
    {
        if (Request.QueryString["tid"] != null && Request.QueryString["op"] == "type")
        {
            YqhData obj = new YqhData();
            AspNetPager1.RecordCount = Convert.ToInt32(obj.ExecuteScalar(string.Format("select count(*) from news where ntypeid={0}", Request.QueryString["tid"])));
            int pageindex = AspNetPager1.CurrentPageIndex - 1;
            int pagesize = AspNetPager1.PageSize;

            string sql = string.Format("select nid,tname,nsubject,ndate=CONVERT(VARCHAR(23),ndate,111) from news inner join newstype on news.ntypeid = newstype.tid where ntypeid={0} order by ndate desc", Request.QueryString["tid"]);
            rpttypelist.DataSource = obj.ExecuteDataSet(sql,pageindex,pagesize);
            rpttypelist.DataBind();
        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        rptdatabind();
    }
}
